package controllers

import (
	"app/daos"
	"app/model"
	. "app/utils"
	"github.com/gin-gonic/gin"
)

type Log struct {
	Dashboard
}

func (l *Log) LogInfo(c *gin.Context) gin.H {
	params, err := GetStructByParams[ID](c)
	if err != nil {
		return l.WarnResponse(ErrCodeIllParams, err.Error())
	}

	lMo := model.NewLogsModel([]int{params.Id})

	if codedErr := lMo.Select(); codedErr.Error != nil {
		return l.WarnResponse(codedErr.Code, codedErr.Error.Error())
	}

	return l.Response(lMo.Record)
}

func (l *Log) LogInfoWithCond(c *gin.Context) gin.H {
	params, err := GetStructByParams[LogInfo](c)
	if err != nil {
		return l.WarnResponse(ErrCodeIllParams, err.Error())
	}

	lMo := model.NewLogsModel()
	if codedErr := lMo.Limit(1).SetCond(daos.Logs{Username: params.Username}).Select(); codedErr.Error != nil {
		return l.WarnResponse(codedErr.Code, codedErr.Error.Error())
	}

	return l.Response(lMo.Record)
}
